const commentModel = require('../models/comment.js')

exports.list = async (req, res, next) => {
	try {
		const {topic_id} = req.query
		const comments = await commentModel.getCommentsByTopicId(topic_id)
		res.status(200).json(comments)
	} catch(err) {
		next(err)
	}
}

exports.create = async (req, res, next) => {
	try {
		let body = req.body
		body.user_id = req.session.user.id
		const id = await commentModel.addComment(body)
		const comment = await commentModel.getCommentById(id)
		res.status(201).json(comment)
	} catch(err) {
		next(err)
	}
}

exports.update = async (req, res, next) => {

}

exports.delete = async (req, res, next) => {

}
